import java.util.ArrayList;

/**
 * Created by forcht on 2018/7/13.
 */
public class Solution {
    public ArrayList<Integer> getRow(int rowIndex) {
        ArrayList<Integer> list = new ArrayList<>();
        int a, b;
        for (int i = 0; i <= rowIndex; i++) {
            a = 1;
            for (int j = 0; j <= i; j++) {
                if (j == i || i == 0) {
                    list.add(1);
                } else if (j == 0) {
                    list.set(j, 1);
                } else {
                    b = list.get(j);
                    list.set(j, a + b);
                    a = b;
                }
            }
        }
        return list;
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.getRow(3));
    }
}
